#pragma once

#include <maya/MString.h>
#include <maya/MStringArray.h>
#include <assert.h>
#include <string>
#include <iostream>

// Current plugin version.
#define PLUGIN_VERSION "0.10"
// The exporter name.
#define EXPORTER_NAME "COLLADA"

using namespace std;

#ifdef _MSC_VER
#define DEBUGGER_BREAK __debugbreak()
#else
#define DEBUGGER_BREAK assert(0)
#endif

#ifdef DEBUG
#define ASSERT(expression) { if (!(expression)) { cout << "assertion fail in " << __FUNCSIG__ << ", line " << __LINE__ << ": " << #expression << endl; DEBUGGER_BREAK; } }
#else
#define ASSERT(expression) 
#endif

#ifdef ERROR
#undef ERROR
#endif
#define ERROR(details) { cout << "error in " << __FUNCSIG__ << ", line " << __LINE__ << ": " << details << endl; }
#define ERROR_AND_RET(details, retval) { cout << "error in " << __FUNCSIG__ << ", line " << __LINE__ << ": " << details << endl; return retval; }

#define BEGIN_ENUM(namespaceName) namespace namespaceName { typedef enum Type {
#define END_ENUM() }; }

// The empty string.
static const string EmptyString = "";

// Converts a datetime value to its ISO 8601 string representation.
// NOTE: destination must be large enough (at least 30 chars long).
void ConvertDateTimeToISO8601Ansi(time_t value, char* destination, size_t length);
// Returns the current OS user name.
string GetCurrentUserName();

// Represents an exception.
class ColladaExporterException
{
public:
	// Constructor.
	ColladaExporterException(const MString& location, const MString& msg) : m_Message(location + msg) { }

	// Returns the exception message.
	const MString& ToString() const { return m_Message; }
private:
	MString		m_Message;
};

#define STRINGIFY(x) #x
#define THROW_EXCEPTION(msg) throw ColladaExporterException(__FUNCSIG__ " (" __FILE__ ":" STRINGIFY(__LINE__) "): ", (msg))
#define CHECK_STATUS_AND_THROW(statusVariable, expression) if (!(statusVariable = (expression))) THROW_EXCEPTION(MString("expression " #expression " failed: ") + statusVariable.errorString())